/*
 * 项目名称:    wms-app-xinpu
 * 创建人员:    DongPeng
 * 创建时间:    2023-02-28
 * copyright(c) 2022 无锡星智数服科技有限公司
 */
package org.jeecg.modules.dock.controller;

import cn.hutool.core.collection.CollectionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.dock.aspect.DockLog;
import org.jeecg.modules.dock.config.JsonUtils;
import org.jeecg.modules.dock.constant.SystemConstants;
import org.jeecg.modules.dock.entity.dto.request.OriginalVolumeUbOrderRequestDTO;
import org.jeecg.modules.dock.entity.dto.response.SapBaseResponseDTO;
import org.jeecg.modules.dock.handler.impl.OriginalVolumeUbOrderHandler;
import org.jeecg.modules.dock.service.SapDataDockingService;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * SAP数据对接接口
 *
 * @author DongPeng
 * @version 1.0.0
 * @date 2023-02-28
 * @description 类描述
 */
@Slf4j
@RestController
@RequestMapping("/dock/sap")
@RequiredArgsConstructor
@Api(tags="SAP数据接收模块")
@DockLog(source = SystemConstants.SAP)
public class SapDockingController {

    private final SapDataDockingService sapDataDockingService;

    /**
     * 接收SAP数据
     *
     * @param business 业务代码
     * @param request  数据
     * @return java.util.List<? extends org.jeecg.modules.dock.entity.dto.response.SapBaseResponseDTO>
     * @author hansen
     * @since 2023/9/14 13:02
     */
    @ApiOperation(value = "接收sap数据", notes = "接收sap数据")
    @PostMapping("/receive")
    @DockLog(source = SystemConstants.SAP,index = 1)
    public Object receiveData(@RequestHeader("business") String business, @RequestBody List<Object> request) {
        List<String> collect = request.stream().map(JsonUtils::toJson).collect(Collectors.toList());
        if(business.equals("A834")){
            List<? extends SapBaseResponseDTO> sapBaseResponseDTOS = sapDataDockingService.dealData(business, collect);
            if(CollectionUtil.isNotEmpty(sapBaseResponseDTOS)){
                return sapBaseResponseDTOS.get(0);
            }
        }
        return sapDataDockingService.dealData(business, collect);
    }

}


